package wangm.util;

import java.util.Random;

public class RandomUtil {
    /**
     * 26*2 = 52
     */
    private static Character[] randomChar = new Character[]{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
            'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
    /**
     * 10
     */
    private static Character[] randomNumber = new Character[]{'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
    /**
     * 随机random
     */
    private static Random random = new Random();

    /**
     * 随机uuid
     *
     * @return String
     */
    public static String getUUID() {
        return getUUID(20);
    }

    /**
     * 随机uuid 指定长度
     *
     * @param number 长度
     * @return String
     */
    public static String getUUID(Integer number) {
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < number; i++) {
            if (random.nextBoolean()) {
                result.append(randomChar[random.nextInt(52)]);
            } else {
                result.append(randomNumber[random.nextInt(10)]);
            }
        }
        return result.toString();
    }

    /**
     * 随机number
     *
     * @return string
     */
    public static String getRandomNumber() {
        return getRandomNumber(15);
    }

    /**
     * 随机number 指定长度
     *
     * @param number number长度
     * @return string
     */
    public static String getRandomNumber(Integer number) {
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < number; i++) {
            result.append(randomNumber[random.nextInt(10)]);
        }
        return result.toString();
    }
}
